<%--
  ** Copyright(c) 2005 BroadVision, Inc. All rights reserved.
  **
  ** This software is copyrighted.  Under the copyright laws, this software
  ** may not be copied, in whole or in part, without prior written consent
  ** of BroadVision, Inc. or its assignees. This software is provided under
  ** the terms of a license between BroadVision and the recipient, and its
  ** use is subject to the terms of that license.
  **
  ** This software may be protected by one or more U.S. and International
  ** patents. Certain applications of BroadVision One-To-One software are
  ** covered by U.S. patent 5,710,887.
  **
  ** TRADEMARKS: BroadVision and the BroadVision logo are registered
  ** trademarks, and BroadVision One-To-One is a trademark of BroadVision,
  ** Inc. IONA and Orbix are trademarks of IONA Technologies, Ltd. RSA,
  ** MD5, and RC2 are trademarks of RSA Data Security, Inc. All other
  ** trademarks, service marks, and trade names belong to their respective
  ** owners. BroadVision, Inc. disclaims any proprietary interest in the
  ** marks and names of others.
  --%>

<%@ taglib uri="/WEB-INF/c.tld" prefix="cx" %>
<%@ taglib uri="/WEB-INF/struts-bean-el.tld" prefix="bean-elx" %>
<%@ taglib uri="/WEB-INF/struts-html-el.tld" prefix="html-elx" %>

<%@ page import="java.io.ByteArrayOutputStream" %>
<%@ page import="java.io.PrintStream" %>
<%@ page import="org.apache.struts.Globals" %>
<%@ page import="org.apache.struts.action.ActionMapping" %>
<%@ page import="com.broadvision.report.admin.ReportConfig" %>
<%@ page import="com.broadvision.report.admin.ConfigException" %>
<%@ page import="com.broadvision.ssp.client.SelfServiceProcess" %>

<%
  final String ctxPath = request.getContextPath();
  final ReportConfig model =
          (ReportConfig)request.getAttribute("runtimeReportConfigModel");
  final SelfServiceProcess sspList[] =
          (SelfServiceProcess[])request.getAttribute("reportConfigProcList");
  if (sspList != null)
      pageContext.setAttribute("sspList", sspList);
  else
      pageContext.setAttribute("sspList", new SelfServiceProcess[] {});

  final String trClassList[] = { "listEven", "listOdd" };
  pageContext.setAttribute("listEvenOrOdd", trClassList);

  final ActionMapping mapping =
                      (ActionMapping)request.getAttribute(Globals.MAPPING_KEY);
  final String reqPath = mapping.getPath() + ".do";
%>

<cx:set var="editImg">
  <img src="<%=ctxPath%>/bp/images/action/icon_edit.gif"
       width="15" height="15" border="0" class="actionIcon"
       alt='<bean-elx:message bundle="cm.messages" key="image.alt.edit"/>'
       title='<bean-elx:message bundle="cm.messages" key="image.alt.edit"/>'
  >
</cx:set>      
<cx:set var="deleteImg">
  <img src="<%=ctxPath%>/bp/images/action/icon_delete.gif"
       width="15" height="15" border="0" class="actionIcon"
       alt='<bean-elx:message bundle="cm.messages" key="image.alt.delete"/>'
       title='<bean-elx:message bundle="cm.messages" key="image.alt.delete"/>'
  >
</cx:set>

<cx:set var="modified" value="${runtimeReportConfigModel.dirty}"/>

<script language="Javascript">
  function doCancel(form)
  {
    var msg = '<bean-elx:message key="bp.report.runtimeReportConfig.confirm.cancel" bundle="bp.messages"/>';

    <cx:if test="${modified}">
    if (!confirm(msg))
      return false;
    </cx:if>

    form.submit();
    return true;
  }

  function doSave(form)
  {
    var msg = '<bean-elx:message key="bp.report.runtimeReportConfig.confirm.save" bundle="bp.messages"/>';

    if (!confirm(msg))
      return false;

    form.submit();
    return true;
  }

  function doDeploy(form)
  {
    var msg = '<bean-elx:message key="bp.report.runtimeReportConfig.confirm.deploy" bundle="bp.messages"/>';

    if (!confirm(msg))
      return false;

    form.submit();
    return true;
  }
</script>

<table class="zoneFive" summary="run-time report config"
       width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td class="pageTitle" valign="top">
      <bean-elx:message
        key="bp.report.runtimeReportConfig.title"
        bundle="bp.messages"
      />
    </td>
    <td class="pageTitle" valign="top" align="right" nowrap>
      <form method="POST" action="<%=ctxPath + reqPath%>">
        <cx:choose>
          <cx:when test="${modified}">
            <html-elx:submit styleClass="inputButton" property="actionSave"
                            onclick="return doSave(this.form)">
              <bean-elx:message key="button.save" bundle="bp.messages"/>
            </html-elx:submit>
          </cx:when>
          <cx:otherwise>
            <html-elx:submit styleClass="inputButton" property="actionDeploy"
                            onclick="return doDeploy(this.form)">
              <bean-elx:message key="button.deploy" bundle="bp.messages"/>
            </html-elx:submit>
          </cx:otherwise>
        </cx:choose>
        &nbsp;&nbsp;
        <html-elx:submit styleClass="inputButton" property="actionCheck">
          <bean-elx:message key="button.check" bundle="bp.messages"/>
        </html-elx:submit>
        <html-elx:submit styleClass="inputButton" property="actionCancel"
                        onclick="return doCancel(this.form)">
          <bean-elx:message key="button.cancel" bundle="bp.messages"/>
        </html-elx:submit>
      </form>
    </td>
  </tr>
  <tr>
    <td valign="top" width="100%" colspan="2">
      <cx:if test="${!empty reportConfigStatusKey}">
        <bean-elx:message key="${reportConfigStatusKey}" bundle="bp.messages"/>
      </cx:if>
      <div class="errorMessage">
        <html-elx:errors bundle="bp.messages"/>
      </div>
      <cx:if test="${!empty reportCheckErrorMsg}">
        <div class="errorMessage">
          <cx:if test="${!empty reportCheckErrorSubjectType}">
            <html-elx:link
                action="/bp/reportConfigEdit/${reportCheckErrorSubjectType}.do"
                name="reportCheckErrorLinkParams">
              <cx:out value="${editImg}" escapeXml="false"/>
            </html-elx:link>
            &nbsp;&nbsp;&nbsp;
          </cx:if>
          <cx:out value="${reportCheckErrorMsg}"/>
        </div>
      </cx:if>
      <%
      final Throwable ex =
              (Throwable)request.getAttribute(Globals.EXCEPTION_KEY);
      if (ex != null) {
          final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
          final PrintStream stream = new PrintStream(buffer);
          ex.printStackTrace(stream);
          stream.close();
          %>
          <pre class="errorMessage"><%=buffer.toString()%></pre>
          <%
      }
      %>
      <div><%@include file="/mc/common/pagetab.jsp"%></div>
    </td>
  </tr>

<!-- =============================================================
  ** vim: set ts=2 expandtab syntax=jsp:
  -->
